//
//  StoreData.m
//  BosidengIphone
//
//  Created by  on 12-1-5.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "StoreData.h"
#import "AppDelegate.h"

@implementation StoreData
@synthesize storeID;
@synthesize brandID;
@synthesize cityID;
@synthesize name;
@synthesize address;
@synthesize zipCode;
@synthesize phone;
@synthesize businessHours;
@synthesize longitude;
@synthesize latitude;

- (id)init {
    if (self = [super init]) {
        ;
    }
    return self;
}

- (void)dealloc {
    [storeID release];
    [brandID release];
    [cityID release];
    [name release];
    [address release];
    [zipCode release];
    [phone release];
    [businessHours release];
    [latitude release];
    [longitude release];
    [super dealloc];
}

- (void)setValue:(NSDictionary *)data {
    [super setValue:data];
    self.storeID = [data objectForKey:@"StoreID"];
    self.brandID = [data objectForKey:@"BrandID"];
    self.cityID = [data objectForKey:@"CityID"];
    self.name = [data objectForKey:@"Name"];
    self.address = [data objectForKey:@"Address"];
    self.zipCode = [data objectForKey:@"ZipCode"];
    self.phone = [data objectForKey:@"Phone"];
    self.businessHours = [data objectForKey:@"BusinessHours"];
    self.latitude = [data objectForKey:@"Latitude"];
    self.longitude = [data objectForKey:@"Longitude"];
}

+ (id)getItemByID:(NSString *)uid {
    return [StoreData findFirstByCriteria:[StoreData getItemQueryString:@"store_i_d" value:uid]];
}

+ (NSArray *)getAllItems {
    NSString *query = [NSString stringWithFormat:@"WHERE language='%@' ORDER BY store_i_d", [AppDelegate getLanguage]];
    return [StoreData findByCriteria:query];
}

+ (NSArray *)getItemsByBrandId:(NSInteger)brandId {
    NSString *query = [NSString stringWithFormat:@"WHERE language='%@' AND brand_i_d='%d' ORDER BY store_i_d", [AppDelegate getLanguage], brandId];
    return [StoreData findByCriteria:query];
}

+ (NSArray *)getItemsByCityId:(NSInteger)cityId {
    NSString *query = [NSString stringWithFormat:@"WHERE language='%@' AND city_i_d='%d' ORDER BY store_i_d", [AppDelegate getLanguage], cityId];
    return [StoreData findByCriteria:query];
}

+ (NSArray *)getItemsByCityId:(NSInteger)cityId brandId:(NSInteger)brandId {
    NSString *query = [NSString stringWithFormat:@"WHERE language='%@' AND city_i_d='%d' AND brand_i_d='%d' ORDER BY store_i_d", [AppDelegate getLanguage], cityId, brandId];
    return [StoreData findByCriteria:query];
}

@end
